import 'package:date_format/date_format.dart';

class DateUtil {
  static String milliseconds2Date(int timestamp) {
    var date = DateTime.fromMillisecondsSinceEpoch(timestamp);
    return date.toLocal().toString().substring(0, 16);
  }

  static String getYMD() {
    DateTime today = new DateTime.now();
    print("时间戳：${today}");
    String dateSlug =
        "${today.year.toString()}-${today.month.toString().padLeft(2, '0')}-${today.day.toString().padLeft(2, '0')}";
    return dateSlug;
  }

  static String getHms() {
    DateTime today = new DateTime.now();
    // print("时间戳：${today}");
    // print(
    //     "时间戳：${today.hour.toString()}---${today.minute}---${today.second.toString()}");
    String dateSlug =
        "${today.hour.toString()}:${today.minute.toString()}:${today.second.toString()}";
    return dateSlug;
  }

  static String getHms2() {
    DateTime today = DateTime.now();
    String dateSlug =
        "${today.hour.toString()}:${today.minute.toString()}:${today.second.toString()}";
    String  date = formatDate(today, [HH,":","nn",":","ss"]);
    // print("时间戳：${date}");
    return date;
  }
}
